package com.example.demo.mapper;

import com.example.demo.entity.Book;
import com.example.demo.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.favorVO;
import com.example.demo.entity.favorlist;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author author
 * @since 2020-11-28
 */
@Mapper
@Repository
public interface UserMapper extends BaseMapper<User> {
    @Select("SELECT b.author , b.id , b.img, b.`name` , b.price , b.publisher ,b.category, c.`name` category1 from favor a , book b , category c where a.user_id = #{id} and a.book_id = b.id and b.category = c.id")
    List<favorVO> getlovebook(Integer id);

    @Select("SELECT * FROM favor WHERE favor.book_id = #{book_id} AND favor.user_id = #{user_id}")
    favorlist getfavor(Integer book_id,Integer user_id);

    @Select("INSERT INTO favor(user_id,book_id) VALUES (#{user_id},#{book_id})")
    void add(Integer user_id,Integer book_id);

    @Select("DELETE FROM favor WHERE(book_id=#{book_id} and user_id=#{user_id}) ")
    void remove(Integer book_id,Integer user_id);
}
